//
//  JBTabBarController.m
//  OCsinaBlog
//
//  Created by jobo on 16/4/24.
//  Copyright © 2016年 jobo. All rights reserved.
//

#import "JBTabBarController.h"
#import "JBMeViewController.h"
#import "JBHomeViewController.h"
#import "JBMessageViewController.h"
#import "JBDiscoverViewController.h"
#import "JBNavigationController.h"
#import "JBTabbar.h"
@interface JBTabBarController ()

@end

@implementation JBTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 把系统的tabbar 换成自己
    JBTabbar *tabbar = [[JBTabbar alloc] init];
#warning 如果类有个readonly属性，使用kvc方式可替换系统的tabbar
    [self setValue:tabbar forKey:@"tabBar"];
    
    
    //设置导航控制器
    
    JBHomeViewController *homeVC = [[JBHomeViewController alloc] init] ;
    [self addChildVC:homeVC withTittle:@"首页" withNolImgName : @"tabbar_home" withSelImgName:@"tabbar_home_selected"];
    
    JBDiscoverViewController *disVC = [[JBDiscoverViewController alloc] init] ;
    [self addChildVC:disVC withTittle:@"发现"withNolImgName : @"tabbar_discover" withSelImgName:@"tabbar_discover_selected"];
    
    JBMessageViewController *messageVC = [[JBMessageViewController alloc] init] ;
    [self addChildVC:messageVC withTittle:@"消息" withNolImgName : @"tabbar_message_center" withSelImgName:@"tabbar_message_center_selected"];
    
    JBMeViewController *meVC = [[JBMeViewController alloc] init];
    [self addChildVC:meVC withTittle:@"我" withNolImgName : @"tabbar_profile" withSelImgName:@"tabbar_profile_selected"];
    
    
}
    
//设置导航控制器的各个元素
-(void)addChildVC : (UIViewController *)vc withTittle:(NSString *) title withNolImgName : (NSString *)nolImgName withSelImgName: (NSString *) selImgName
{
    JBNavigationController *nav = [[JBNavigationController alloc] initWithRootViewController:vc] ;
    
    [self addChildViewController:nav];
    
    nav.tabBarItem.title = title ;
    
    nav.tabBarItem.image = [UIImage imageNamed:nolImgName] ;
    
    //设置图片渲染效果为橘黄色
    UIImage *selImg = [UIImage imageNamed:selImgName] ;
    selImg = [selImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ;
    
    nav.tabBarItem.selectedImage = selImg;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
